<html>
<head><title>11-712 NLP Lab</title></head>
<body bgcolor="#FFFFFF">
<h1 align=center>Language Technologies Institute<br>11-712: Self-Paced Laboratory</h1>

<hr>

<h1>Algorithms for NLP:<br>
GLR Module Instructions</h1>

<p><i>NLP researchers working on large projects are frequently asked to
fix partially working code, or to update existing code to improve or
extend its functionality. In this assignment, you are presented with a
hypothetical scenario which involves both fixing and extending a
pre-existing parsing module.</i></p>

<hr>

<h3>Day 1</h3>

<p>Your advisor calls you into his office to relay some discouraging
news. Narley Q. Hacker, a second-year grad student on your project,
has left CMU for a job writing Java applets at corporate giant
Acmesoft. Unfortunately, Narly was right in the middle of prototyping
a new syntactic parser for the project, and was only half done when he
left. There is very little documentation. But your job will be to
analyze the existing code and figure out how to complete it, while
fixing any bugs that Narley left behind. Your advisor gives you a
pointer to the rough <a href="design.html">design specs</a> that he
supplied initially. As you leave your advisor's office, you wonder
what kind of shape Narley's code is in, and you silently swear never
to buy an Acmesoft product again.</p>

<hr>

<h3>Day 2</h3>

<p>Having read the design specs, you decide to check out the current state of the code. You fire up Lisp, and load the given code file:</p>
<p align=center><a href="given-code.lisp">/afs/cs/project/cmt-55/lti/Lab/Modules/NLP-712/glr/given-code.lisp</a></p>

<p>You note that the code loads without errors -- at least Narley left
the files in a stable state. However, looking at the trace output, you
note that the lexicons contain only one entry each:</p>
<pre>
SYNLEX: ("man" (CAT N) (SEM *O-MAN-1))
SEMLEX: (*O-MAN-1 (=IS-A &O_ANIMATE))
</pre>

<p>You take a look at the grammar file, and realize that Narley never
implemented the lexical lookup function that your advisor was talking
about; instead, there are just a bunch of lexical rules hard-wired
into the grammar:</p>

<pre>
;; Temporary lexical rules

(&lt;n&gt; &lt;-- (boy)
     (((x0 root) = boy)
      ((x0 number) = sg)
      ((x0 cat) = n)))

(&lt;n&gt; &lt;-- (boys)
     (((x0 root) = boy)
      ((x0 number) = pl)
      ((x0 cat) = n)))

(&lt;v&gt; &lt;-- (see)
     (((x0 root) = see)
      ((x0 valency) = (*or* trans intrans))
      ((x0 cat) = v)))

(&lt;det&gt; &lt;-- (the)
     (((x0 root) = the)
      ((x0 cat) = det)))

(&lt;det&gt; &lt;-- (a)
     (((x0 root) = a)
      ((x0 cat) = det)))

(&lt;p&gt; &lt;-- (with)
     (((x0 root) = with)
      ((x0 cat) = p)))
</pre>

<p>You decide to experiment a little bit, and find that the grammar seems to work on some cases:</p>
<pre>
&gt;(parser boy)

((CAT N) (NUMBER SG) (ROOT BOY))
NIL

&gt;(parser the boy)

((CAT N) (NUMBER SG) (ROOT BOY)
 (DET
    ((CAT DET) (ROOT THE))))
NIL

&gt;(parser the boys see)

((MOOD DECLARATIVE) (VALENCY INTRANS) (CAT V) (ROOT SEE)
 (SUBJ
    ((CAT N) (NUMBER PL) (ROOT BOY)
     (DET
        ((CAT DET) (ROOT THE))))))
NIL

</pre>

<p>However, there are definitely examples where the existing grammar doesn't meet the design specification:</p>

<pre>
&gt;(parser the boy see)

((MOOD DECLARATIVE) (VALENCY INTRANS) (CAT V) (ROOT SEE)
 (SUBJ
    ((CAT N) (NUMBER SG) (ROOT BOY)
     (DET
        ((CAT DET) (ROOT THE))))))
NIL

&gt;(parser a boys)

((CAT N) (NUMBER PL) (ROOT BOY)
 (DET
    ((CAT DET) (ROOT A))))
NIL
</pre>

<hr>

<h3>Day 3</h3>

<p>You implement the features that are required for proper DET-N and
NP-VP (subject object) agreement by changing the hard-wired lexical
rules and the appropriate rules for NP and S. </p>

<hr>

<h3>Day 4</h3>

<p>You remove the hard-wired lexical rules from the grammar, and put them
into the lexicon file in the proper format. Then you add the
callout-based lexical rules for N, V, P and DET, as shown in the
design specs.</p>

<p>You experiment by calling the built-in function
<code>parse-eng-morph</code> on some inflected strings like "sees",
"boys", etc.</p>

<p>Having loaded in your syntactic lexicon using the given
<code>load-lexicon</code> function, you write your version of
<code>parse-eng-word</code> as per the data specs.</p>

<p>You test your version of <code>parse-eng-word</code> by running it by hand on  some sample strings.</p>

<p>Finally, you integrate your version of <code>parse-eng-word</code>
by recompiling the grammar and running some tests using the
<code>parser</code> macro.</p>

<hr>

<h3>Day 5</h3>

<p>You notice that the basic given system allows ambiguous attachment of PP to NP and VP:</p>
<pre>
&gt;(parser the boy sees the boy with the boy)

((ROOT SEE) (CAT V) (VALENCY TRANS) (MOOD DECLARATIVE)
 (OBJ
    ((CAT N) (NUMBER SG) (ROOT BOY)
     (PPADJUNCT
        ((CAT P) (ROOT WITH)
         (OBJ
            ((CAT N) (NUMBER SG) (ROOT BOY)
             (DET
                ((CAT DET) (ROOT THE)))))))
     (DET
        ((CAT DET) (ROOT THE)))))
 (SUBJ
    ((CAT N) (NUMBER SG) (ROOT BOY)
     (DET
        ((CAT DET) (ROOT THE))))))

((ROOT SEE) (CAT V) (VALENCY TRANS) (MOOD DECLARATIVE)
 (OBJ
    ((CAT N) (NUMBER SG) (ROOT BOY)
     (DET
        ((CAT DET) (ROOT THE)))))
 (PPADJUNCT
    ((CAT P) (ROOT WITH)
     (OBJ
        ((CAT N) (NUMBER SG) (ROOT BOY)
         (DET
            ((CAT DET) (ROOT THE)))))))
 (SUBJ
    ((CAT N) (NUMBER SG) (ROOT BOY)
     (DET
        ((CAT DET) (ROOT THE))))))
NIL
</pre>

<p>Following your advisor's instructions in the design specs, you
write a callout called <code>license-attachment</code>, and rewrite
the rules that attach PP to NP and VP to use that callout.</p>

<p>In order to get the right attachment licensed, you'll have to write
the correct entries into the semantic lexicon. Use the design specs,
which describe the proper format of frames, is-a relations, and
semantic roles, to write frames that capture the hierarchy
fragment given in the design specs.</p>


<p>(Hint: you will need to encode the <code>semrole</code> for "with"
in your syntactic lexicon using the <code>*OR*</code> operator, since
"with" can map to either <code>+INSTRUMENT</code> or
<code>+ACCOMPLICE</code>.)</p>


<p>If you've gotten it all put together correctly, then the previously ambiguous sentence will have only one legal attachment for PP, and you'll have something like this coming out:</p>
<pre>
&gt;(parser the men see the boys with the telescope)

** ATTACH FAILED (*O-BOY-1 (+INSTRUMENT *O-TELESCOPE-1))
** ATTACH FAILED (*O-BOY-1 (+ACCOMPLICE *O-TELESCOPE-1))
** ATTACHING (*A-SEE-1 (+INSTRUMENT *O-TELESCOPE-1))
** ATTACH FAILED (*A-SEE-1 (+ACCOMPLICE *O-TELESCOPE-1))
((MOOD DECLARATIVE) (NUMBER PL) (PERSON 3) (VALENCY TRANS)
 (CAT V) (ROOT "see") (SEM *A-SEE-1)
 (SUBJ
    ((CAT N) (PERSON 3) (ROOT "men") (NUMBER PL) (SEM *O-MAN-1)
     (DET
        ((NUMBER PL) (CAT DET) (ROOT "the") (REFERENCE DEFINITE)))))
 (OBJ
    ((CAT N) (NUMBER PL) (PERSON 3) (ROOT "boy") (SEM *O-BOY-1)
     (DET
        ((NUMBER PL) (CAT DET) (ROOT "the") (REFERENCE DEFINITE)))))
 (PPADJUNCT
    ((CAT P) (ROOT "with") (SEMROLE +INSTRUMENT)
     (OBJ
        ((CAT N) (NUMBER SG) (PERSON 3) (ROOT "telescope")
         (SEM *O-TELESCOPE-1)
         (DET
            ((NUMBER SG) (CAT DET) (ROOT "the") (REFERENCE DEFINITE))))))))
NIL
</pre>

<hr>

<h3>Day 6</h3>

<p>You test your code by loading the test file:</p>
<p align=center><a href="test-code.lisp">/afs/cs/project/cmt-55/lti/Lab/Modules/NLP-712/glr/test-code.lisp</a></p>

<p>Call the function <code>(run-tests)</code>. Once you fix any
remaining bugs, you're ready to comment your code and hand it in!
(Note: the output of <code>(run-tests)</code> should be placed in a
file called test-output.txt in your handin directory.)  </p>

<hr>

<i>5-Nov-96 by <a href="mailto:ehn@cs.cmu.edu">ehn@cs.cmu.edu</a></i>
</body>
</html>
